package com.kingre.et.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.context.SecurityContextHolder;

import com.kingre.et.model.School;
import com.kingre.et.model.User;
import com.kingre.et.service.ISchoolService;
import com.opensymphony.xwork2.ActionSupport;

public class SchoolManagerAction extends ActionSupport {
    private static final long serialVersionUID = -7574224667101812948L;
    private static final Logger logger = Logger.getLogger(SchoolManagerAction.class);
    private String roleName;
    @Autowired
    private ISchoolService schoolService;
    private List<School> schoolList = new ArrayList<School>();
    
    private String name;
    private Integer id;
    private String schoolName;
    private String schoolType;

    public String execute(){
    	User currentUser = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        roleName = SecurityContextHolder.getContext().getAuthentication().getAuthorities()[0].getAuthority();
        schoolList = schoolService.find(currentUser.getId(), name);
        return SUCCESS;
    }
    public String delete(){
        logger.debug("id =" + id);
        schoolService.delete(id);
        return execute();
    }
    public String add(){
        logger.debug("schoolName =" + schoolName);
        logger.debug("schoolType =" + schoolType);
        schoolService.add(schoolName, schoolType, id);
        addFieldError("dd", getText("user.add.ok"));
        return execute();
    }
    
    public String update(){
        logger.debug("id =" + id);
        schoolService.updateConsult(id);
        return execute();
    }
    
    public List<School> getSchoolList() {
        return schoolList;
    }
    public void setSchoolList(List<School> schoolList) {
        this.schoolList = schoolList;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getSchoolName() {
        return schoolName;
    }
    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }
    public String getRoleName() {
        return roleName;
    }
    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }
	public String getSchoolType() {
		return schoolType;
	}
	public void setSchoolType(String schoolType) {
		this.schoolType = schoolType;
	}

}
